// pages/personalCenter/personalCenter.js
const app = getApp();
import CommonService from '../../utils/service/commonService.js';
import * as echarts from '../../ec-canvas/echarts';
const util = require('../../utils/util');
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';

//图表对象
let Chart1 = null;
let Chart2 = null;
let Chart3 = null;
let Chart4 = null;
let Chart5 = null;
let Chart6 = null;

//去掉尾部的0
const regexp = /(?:\.0*|(\.\d+?)0+)$/;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showHelp: false,
        //图片前缀
        prefix: 'http://bangnizu.oss-cn-hangzhou.aliyuncs.com/bangni/images/',
        //菜单列表
        menuList: [],
        //用户信息
        user: {},
        //权限
        authority: {},
        //图表
        ec1: {
            //延迟加载
            lazyLoad: true
        },
        ec2: {
            lazyLoad: true
        },
        ec3: {
            lazyLoad: true
        },
        ec4: {
            lazyLoad: true
        },
        ec5: {
            lazyLoad: true
        },
        ec6: {
            lazyLoad: true
        },
        //是否显示图表（避免遮挡）
        showChart1: true,
        showChart2: true,
        showChart3: true,
        showChart4: true,
        showChart5: true,
        showChart6: true,
        //无数据
        showNoData1: false,
        showNoData2: false,
        showNoData3: false,
        showNoData4: false,
        showNoData5: false,
        showNoData6: false,
        //图表配置
        chartSet1: {
            //图表类型
            type: 'line',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: ''
        },
        chartSet2: {
            //图表类型
            type: 'bar',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: '（%）'
        },
        chartSet3: {
            //图表类型
            type: 'bar',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: '小时'
        },
        chartSet4: {
            //图表类型
            type: 'bar',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: '（%）'
        },
        chartSet5: {
            //图表类型
            type: 'bar',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: '小时'
        },
        chartSet6: {
            //图表类型
            type: 'bar',
            //颜色
            barColor: '#ccc',
            //y轴标题
            title: '%'
        },
        //项目id
        projectId: null,
        //显示用户名
        currentName: '',
        //显示部门
        currentDepart: '',
        //简报看板数据
        boardData: {},
        all: 0,
        todayNum: 0,
        recent3: 0,
        recent7: 0,
        recent15: 0,
        repairNum: 0,
        unUseEquipmentCount: 0,
        battery: 0,
        //是否显示效率排名
        showEfficiency: false,
        //是否显示设备报价单
        showPrice: true,
        //是否显示售后功能
        commonShowAfter: true,
        //是否显示工牌内容
        showCard: false,

        showDepartData: false,
        //在管人数
        allUser: 0,
        //人员信息数量
        userNumInfo: null,
        //设备运行时长图表高度
        chartHeight: 0,
        //设备类型出勤率图表高度
        chartHeight1: 0,
        //显示图表（设备类型出勤率、设备运行时长）
        showEqChart: false,
        //日历范围，默认最近7天
        dateRange: [util.countPrevDay(new Date(), 6), new Date().getTime()],
        //显示日历
        showDate: false,
        //最小值为两个月前
        minDate: util.countPrevDay(new Date(), 62),
        //最大值为今天
        maxDate: new Date().getTime(),
        //开始日期
        startTime: util.timeFormatDay(util.countPrevDay(new Date(), 6)),
        //结束日期
        endTime: util.timeFormatDay(new Date()),
        //显示底部菜单
        showTabbar: true,
        showNumMenu: []
    },

    goToTest() {
        wx.redirectTo({
            url: "/packageA/pages/dataCollector/dataCollector"
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //是否显示帮助中心，设备报价单，售后
        this.setData({
            showHelp: app.globalData.showHelp,
            showPrice: app.globalData.showPrice,
            commonShowAfter: app.globalData.commonShowAfter
        })
        let currentUser = app.globalData.userInfo;
        let authority = app.globalData.authority;
        
        console.log("currentUser");
        console.log(currentUser);
        console.log("authority");
        console.log(authority);
        if (currentUser) {
            //登录用户
            this.setData({
                user: currentUser,
                currentName: currentUser.userName,
                currentDepart: currentUser.departObj[0].name,
                authority: app.globalData.authority
            })
          
            console.log("authority");
            //是否是员工
            if ((authority.manage && authority.manage.userCard && authority.manage.userCard.staff) || currentUser.role.includes(40)) {
                this.setData({
                    showDepartData: false
                })
            } else {
                this.setData({
                    showDepartData: true
                })
            }

            //非厂家显示工牌相关内容
            let dObj = currentUser.departObj[0];
            console.log("currentUsercurrentUsercurrentUser")
            console.log(currentUser)
            // if (dObj.companyId != 100040 && dObj.companyId != 101078 && dObj.companyId != 101700 && currentUser.departObj[0].type != 2) {
            //     this.setData({
            //         showCard: true
            //     })
            // }
            if ((authority.manage && authority.manage.userCard) || (authority.user)) {
              this.setData({
                showCard: true
              })
            }


            //临时加：西安新壹城（龙湖集团下级）显示工牌
            if (dObj.id == 100573) {
                this.setData({
                    showCard: true
                })
            }
            
           

            //是否显示效率排名
            if (currentUser.departObj[0].hasReport == true) {
                this.setData({
                    showEfficiency: true
                })
            }
        } else {
            wx.redirectTo({
                url: "/pages/login/login"
            })
        }
    },


    async init(){
        //获取未处理完成的工单和未审核的工单
        const list = await this.getUnFinishTaskAndCleanOrder();
        console.log("list")
        console.log(list)
        this.setData({
          showNumMenu:list
        })
         //获取菜单列表
         this.getMenuList();
    },

    //统计范围：任务清单，物业工单
    //统计工单管理里面（任务清单，物业工单）未处理的消息条数/未审批的消息条数
    //如果是一级账号或者区域账号登录的，统计未审批的消息条数
    //如果是项目主管账号，统计未完成的消息条数
    getUnFinishTaskAndCleanOrder(){
      return new Promise((resolve, reject) => {
        const departObj = this.data.user.departObj[0]
        let sign = "projectAdministrator"
        if (departObj.isRegion || departObj.level === 1){
           sign = "approver"
        }else if (departObj.isProject){
          sign = "projectAdministrator"
        }
        let param = {
          sign:sign,
          userId:this.data.user.id,
          memberId:departObj.id
        }
        CommonService.getUnFinishTaskAndCleanOrderFunc(param).then(res => {
          if (res.data.data && res.data.data.result != null) {
              let result = res.data.data.result;
              console.log(result);
              // this.setData({
              //   showNumMenu:result
              // })
              resolve(result); // 成功时返回userId
          } else {
            resolve([{
              id:263,
              name: "工单管理",
              children: [{
                      id:385,
                      name: "任务清单",
                      num: 0
                  },
                  {
                      id:277,
                      name: "物业工单",
                      num: 0
                  }
              ],
          }]);
          }
      })

      }).catch((error) => {
        resolve(null);
      });

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        //页面请求写在onShow中，这样从其他页面返回到这里时，数据是最新的
        let currentUser = app.globalData.userInfo;
        if (currentUser) {
            //简报看板
            this.getDataCount();

            //人员出勤率
            this.personRate();

            //设备出勤率
            this.findEquipmentAllRate();

            //设备类型出勤率、设备运行时长
            this.getChartData();   
            
            this.init();
        }
    },
    //获取菜单列表
    getMenuList() {
      console.log("获取菜单");
        let user = this.data.user;
        let param = {
            //appId: app.globalData.myAppId,
            appId: 3
        }
        CommonService.getMenu(param).then(res => {
            if (res.data.data) {
                let result = res.data.data;
                console.log("caidan");
                console.log(result);
                //去掉原来的菜单
                let arr = [];
                result.forEach(item => {
                    if (item.id != 86 && item.id != 98) {
                        //处理权限
                        if (this.checkKey(item.perms)) {
                            item.showMenu = true;
                        } else {
                            item.showMenu = false;
                        }

                        let has = false;
                        for (let i = 0; i < this.data.showNumMenu.length; i++) {
                            let menuNum = this.data.showNumMenu[i] 
                            if (item.id === menuNum.id) {
                                let num = 0
                                for (let j = 0; j < menuNum.children.length; j++) {
                                    let c = menuNum.children[j]
                                    num += c.num;
                                }
                                item.unFinishNum = num > 99 ? "99+" : num;
                                item.showUnFinishNum = num > 0;
                                has = true
                                break;
                            }
                        }

                        if (!has) {
                            item.showUnFinishNum = false;
                            item.unFinishNum = 0;
                        }

                        //处理图标
                        if (item.icon) {
                            item.iconColor = item.icon.split(':');
                        }

                        //龙湖集团隐藏售后服务、工单管理、人员管理
                        let dObj = user.departObj[0];
                        if (dObj.companyId == 100040 && dObj.id != 100573) {
                            if (item.id != 266 && item.id != 263 && item.id != 256) {
                                arr.push(item);
                            }
                        }
                        //佛山智科机器人不显示人员管理
                        else if (dObj.companyId == 101078 || dObj.companyId == 101700) {
                            if (item.id != 256) {
                                arr.push(item);
                            }
                        }
                        //西安新壹城（龙湖集团下级）显示工牌，不显示售后服务、工单管理
                        else if (dObj.id == 100573) {
                            if (item.id != 266 && item.id != 263) {
                                arr.push(item);
                            }
                        } else {
                            arr.push(item);
                        }
                    }
                });

                //按ordernum排序
                arr.sort(util.compareobjectArray('ordernum', 1));

                console.log('菜单列表');
                console.log(arr);

                this.setData({
                    menuList: arr
                })
            }
        }).catch((error) => {})
    },

    //菜单根据权限来显示
    checkKey(authority) {
        let currentRole = this.data.authority;
        let authArr = authority.split(':');
        let checkResult = true;

        authArr.forEach((auth, index) => {
            if (index == 0) {
                if (currentRole[auth] && currentRole[auth] != undefined) {
                    if (currentRole[auth] == {}) {
                        checkResult = false;
                    } else {
                        checkResult = currentRole[auth];
                    }
                } else {
                    checkResult = false;
                }
            } else {
                if (checkResult[auth] && checkResult[auth] != undefined) {
                    if (checkResult[auth] == {}) {
                        checkResult = false;
                    } else {
                        checkResult = checkResult[auth];
                    }
                } else {
                    checkResult = false;
                }
            }
        });

        return checkResult;
    },

    //点击菜单
    goToUrl({
        currentTarget
    }) {
        let detail = currentTarget.dataset.detail;

        let menuNum = []

        for (let i = 0; i < this.data.showNumMenu.length; i++) {
            let menu = this.data.showNumMenu[i];
            if (menu.name === detail.title) {
                menuNum = menu.children;
                break;
            }
        }

        let obj = {
            id: detail.id,
            title: detail.title,
            menuNum: menuNum
        }

        console.log(detail);
        wx.navigateTo({
            url: "/pages/menu/menu?paramObj=" + JSON.stringify(obj)
        })
    },

    goToReminderOfNonCompliance() {
        console.log('123')
        wx.navigateTo({
            url: '/packageA/pages/reminderOfNonCompliance/reminderOfNonCompliance',
        })
    },

    //跳转到未开发页面
    goToNot() {
        wx.navigateTo({
            url: '/pages/certificate/certificate',
        })
    },

    //跳转设置
    goToSet() {
        wx.navigateTo({
            url: '/pages/set/set'
        })
    },

    //数据面板数据
    getDataCount() {
        //近几天未使用，本页面不用这个数据，随意传值就好
        let param = {
            minRange: 0,
            midRange: 0,
            maxRange: 0
        }

        CommonService.personCenterCounts(param).then(res => {
            if (res.data.data && res.data.data.all != null) {
                let result = res.data.data;
                console.log('简报看板');
                console.log(result);

                this.setData({
                    boardData: result,
                    all: result.all ? result.all.length : 0,
                    todayNum: result.countToday ? result.countToday.length : 0,
                    // recent3: result.count3Day ? result.count3Day.length : 0,
                    // recent7: result.count7Day ? result.count7Day.length : 0,
                    // recent15: result.count15Day ? result.count15Day.length : 0,
                    repairNum: result.countRepair ? result.countRepair.length : 0,
                    battery: result.lowPower ? result.lowPower.length : 0,
                    unUseEquipmentCount: result.unUseEquipmentCount ? result.unUseEquipmentCount.length : 0,
                    scrapEquipmentArr:result.scrapEquipmentArr ? result.scrapEquipmentArr.length : 0
                })
            } else {
                this.setData({
                    showNoData2: true,
                    showChart2: false
                })
            }
        }).catch((error) => {
            this.setData({
                showNoData2: true,
                showChart2: false
            })
        })
    },

    //点击总设备
    goToEquipment() {
        wx.navigateTo({
            url: "/pages/equipmentList/equipmentList"
        })
    },

    //点击简报看板
    goToSomeEquipment(e) {
        let key = e.currentTarget.dataset.key;
        let boardData = this.data.boardData;
        console.log(boardData);
        let arr = boardData[key];
        //跳转设备列表并传参imei
        if (arr && arr.length) {
            wx.navigateTo({
                url: "/pages/equipmentList/equipmentList?imeiArr=" + JSON.stringify(arr)
            })
        }
    },

    //判断图表是否第一次绘制
    isHaveChart(chartObj, componnetObj, setObj, dataObj, HorV, colors) {
        if (!chartObj) {
            //如果是第一次绘制，则初始化图表
            this.init_echarts(chartObj, componnetObj, setObj, dataObj, HorV, colors);
        } else {
            //更新图表数据
            this.setOption(chartObj, setObj, dataObj, HorV, colors);
        }
    },

    //初始化图表
    init_echarts(chartObj, componnetObj, setObj, dataObj, HorV, colors) {
        componnetObj.init((canvas, width, height, dpr) => {
            chartObj = echarts.init(canvas, null, {
                width: width,
                height: height,
                devicePixelRatio: dpr
            });

            canvas.setChart(chartObj);

            this.setOption(chartObj, setObj, dataObj, HorV, colors);

            return chartObj;
        });
    },

    //测试跳转
    testSubmit(){
      let obj = {
        projectId:102341,
        sign:"week"
      }
      wx.navigateTo({
        url: "/packageA/pages/reminderOfNonCompliance/reminderOfNonCompliance?projectId=${102341}&sign=${day}"
      })  
    },


    //更新图表数据
    setOption(chartObj, setObj, dataObj, HorV, colors) {
        //清除
        chartObj.clear();

        //设置新数据
        if (HorV == 'vertical') {
            //竖排图表
            chartObj.setOption(this.getOptionV(chartObj, setObj, dataObj, colors));
        } else {
            //横排图表
            chartObj.setOption(this.getOption(chartObj, setObj, dataObj));
        }
    },

    //指定图表的配置项和数据
    getOption(chartObj, setObj, dataObj) {
        //文字颜色
        let fontColor = '#666';

        let option = {
            legend: {
                textStyle: {
                    color: '#666',
                    padding: [0, 30, 0, 0]
                },
                x: 'right',
                y: 'top'
            },
            grid: {
                left: '2%',
                right: '3%',
                top: '15%',
                bottom: '7%',
                containLabel: true,
            },
            xAxis: {
                type: 'category',
                axisLabel: {
                    color: fontColor,
                    fontSize: 12,
                    interval: 0,
                    //rotate:10
                },
                axisLine: {
                    lineStyle: {
                        color: setObj.barColor
                    }
                },
                data: dataObj.xData,
            },
            yAxis: {
                type: 'value',
                name: setObj.title,
                nameTextStyle: {
                    fontSize: 13,
                    color: '#777',
                },
                axisLabel: {
                    color: fontColor,
                    fontSize: 13,
                },
                axisLine: {
                    lineStyle: {
                        color: setObj.barColor
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: '#eee'
                    }
                }
            },
            series: dataObj.yData
        };

        return option;
    },

    //指定图表的配置项和数据
    getOptionV(chartObj, setObj, dataObj, colors) {
        //文字颜色
        let fontColor = '#666';

        let option = {
            color: colors,
            grid: {
                left: '4%',
                right: '16%',
                top: '15%',
                bottom: '5%',
                containLabel: true,
            },
            legend: {
                textStyle: {
                    color: '#666'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            yAxis: {
                type: 'category',
                name: '日期',
                nameTextStyle: {
                    fontSize: 13,
                    color: '#777',
                },
                axisLabel: {
                    color: fontColor,
                    fontSize: 13,
                },
                axisLine: {
                    lineStyle: {
                        color: setObj.barColor
                    }
                },
                data: dataObj.xData,
            },
            xAxis: {
                type: 'value',
                name: setObj.title,
                nameTextStyle: {
                    fontSize: 13,
                    color: '#777',
                },
                axisLabel: {
                    color: fontColor,
                    fontSize: 12
                },
                axisLine: {
                    lineStyle: {
                        color: setObj.barColor
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: '#eee'
                    }
                }
            },
            series: dataObj.yData
        };

        return option;
    },

    //隐藏图表
    hideChart() {
        this.setData({
            showChart1: false,
            showChart2: false,
            showChart5: false,
            showChart6: false
        })
    },

    //显示图表
    showChart() {
        this.setData({
            showChart1: true,
            showChart2: true,
            showChart5: false,
            showChart6: false
        })
    },

    //帮助中心
    goToVideo() {
        wx.navigateTo({
            url: '/packageA/pages/helpCenter/helpCenter'
        })
    },

    //跳转人员列表
    goToUserList() {
        wx.navigateTo({
            url: '/packageA/pages/userList/userList'
        })
    },

    //人员出勤率
    personRate() {
        //图表组件
        this.echartsComponnet4 = this.selectComponent('#mychart4');

        let param = {
            beginDate: this.data.startTime,
            endDate: this.data.endTime
        }

        CommonService.personnelAttendanceRate(param).then(res => {
            if (res.data.data && res.data.data.result) {
                let result = res.data.data.result;
                console.log('人员出勤率');
                console.log(result);

                this.setData({
                    //总人数
                    allUser: result.allCount,
                    //其他需要跳转的人员数量（注意字段保持一致）
                    userNumInfo: {
                        //  在岗人数
                        attendanceCount: result.attendanceCount && result.attendanceCount.length ? result.attendanceCount : [],
                        //  缺岗人数
                        lackOfPostCount: result.lackOfPostCount && result.lackOfPostCount.length ? result.lackOfPostCount : [],
                        //  请假人数
                        askForLeave: result.askForLeave && result.askForLeave.length ? result.askForLeave : [],
                    }
                })

                if (result.attendanceRate && result.attendanceRate.length) {
                    this.setData({
                        showNoData4: false,
                        showChart4: true
                    })

                    //数据全为0时的处理
                    let flag = result.attendanceRate.every(val => {
                        return val.value == 0;
                    });

                    if (flag) {
                        this.setData({
                            showNoData4: true,
                            showChart4: false
                        })
                    } else {
                        //图表数据
                        let xData = [];
                        let yData = [];

                        result.attendanceRate.forEach(item => {
                            xData.push(item.day.slice(5));
                            yData.push(item.value + '');
                        });

                        let chartData = {
                            xData: xData,
                            yData: [{
                                type: 'bar',
                                data: yData,
                                barWidth: '15px',
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'top',
                                            color: "#80242d"
                                        },
                                        color: new echarts.graphic.LinearGradient(
                                            0, 0, 0, 1,
                                            [{
                                                offset: 0,
                                                color: '#ECA820'
                                            }, {
                                                offset: 1,
                                                color: '#C44142'
                                            }]
                                        )
                                    }
                                }
                            }]
                        }

                        console.log('人员出勤率图表数据');
                        console.log(chartData);

                        //判断图表是否第一次绘制
                        this.isHaveChart(Chart4, this.echartsComponnet4, this.data.chartSet4, chartData);
                    }

                } else {
                    this.setData({
                        showNoData4: true,
                        showChart4: false
                    })
                }
            } else {
                this.setData({
                    showNoData4: true,
                    showChart4: false
                })
            }
        }).catch((error) => {
            this.setData({
                showNoData4: true,
                showChart4: false
            })
        })
    },

    //跳转相应人员
    goToSomeUser({
        currentTarget
    }) {
        let key = currentTarget.dataset.key;
        let info = this.data.userNumInfo;
        let imei = info[key];

        //跳转人员列表并传参imei
        if (imei && imei.length) {
            let obj = {
                imeis: imei
            }
            console.log("!!!!!!!!!!!!!!!!!!!!!!!!!");
            console.log(obj);
            wx.navigateTo({
                url: "/packageA/pages/userList/userList?paramObj=" + JSON.stringify(obj)
            })
        }
    },

    //设备出勤率
    findEquipmentAllRate() {
        Toast.loading({
            duration: 0,
            forbidClick: false,
            message: '图表加载中...'
        });

        let param = {
            begin: this.data.startTime,
            end: this.data.endTime,
            isProject: false
        }

        CommonService.findEquipmentAllRate(param).then(res => {
            if (res.data.data && res.data.data.result) {
                let result = res.data.data.result;
                if (result.rateAllData && result.rateAllData.length) {
                    //显示图表
                    this.setData({
                        showNoData2: false,
                        showChart2: true
                    })

                    let rateAllData = result.rateAllData[0].attendance;
                    console.log('设备出勤率');
                    console.log(rateAllData);

                    //处理图表数据
                    this.chartRateAll(rateAllData);
                } else {
                    this.setData({
                        showNoData2: true,
                        showChart2: false
                    })
                }
            } else {
                this.setData({
                    showNoData2: true,
                    showChart2: false
                })
                Toast.clear();
            }
        }).catch((error) => {
            this.setData({
                showNoData2: true,
                showChart2: false
            })
            Toast.clear();
        })
    },

    //设备类型出勤率、设备运行时长
    getChartData() {
        Toast.loading({
            duration: 0,
            forbidClick: false,
            message: '图表加载中...'
        });

        let dObj = this.data.user.departObj[0];

        //是否显示图表（现在只有龙湖和佛山智科机器人显示）
        // if(dObj.companyId==100040 || dObj.companyId==101078 || dObj.companyId==101700){
        this.setData({
            showEqChart: true
        })

        let param = {
            begin: this.data.startTime,
            end: this.data.endTime,
            isProject: false
        }

        //传参isProject
        if (dObj.isProject && dObj.companyId === 100040) {
            //项目登录
            param.isProject = true;
        } else {
            //总部和大区登录
            param.isProject = false;
        }

        CommonService.findEquipmentGroupCategoryNew(param).then(res => {
            if (res.data.data && res.data.data.result) {
                let result = res.data.data.result;
                console.log('设备类型出勤率、设备运行时长');
                console.log(result);

                //设备类型出勤率
                if (result.rateData && result.rateData.length) {
                    this.setData({
                        showNoData6: false,
                        showChart6: true
                    })

                    //图表高度由设备类型数量确定
                    this.setData({
                        chartHeight1: result.rateData.length * 70 * 7
                    })

                    let rateData = result.rateData;
                    console.log('设备类型出勤率');
                    console.log(rateData);

                    //处理图表数据
                    this.chartRateType(rateData);
                } else {
                    this.setData({
                        showNoData6: true,
                        showChart6: false
                    })
                }

                //设备运行时长
                if (result.hourData && result.hourData.length) {
                    this.setData({
                        showNoData5: false,
                        showChart5: true
                    })

                    //图表高度由设备类型数量确定
                    this.setData({
                        chartHeight: result.hourData.length * 70 * 7
                    })

                    let hourData = result.hourData;
                    console.log('设备运行时长');
                    console.log(hourData);

                    //处理图表数据
                    this.chartHour(hourData);
                } else {
                    this.setData({
                        showNoData5: true,
                        showChart5: false
                    })
                    Toast.clear();
                }
            } else {
                this.setData({
                    showNoData6: true,
                    showChart6: false,
                    showNoData5: true,
                    showChart5: false
                })
                Toast.clear();
            }
        }).catch((error) => {
            this.setData({
                showNoData6: true,
                showChart6: false,
                showNoData5: true,
                showChart5: false
            })
            Toast.clear();
        })
        // }else{
        // 	Toast.clear();
        // }
    },

    //处理图表数据-设备出勤率
    chartRateAll(result) {
        //图表组件-设备出勤率
        this.echartsComponnet2 = this.selectComponent('#mychart2');

        let xData = [];
        let yData = [];
        for (let i = 0; i < result.length; i++) {
            xData.push(result[i].day);
            let rate = (result[i].rate * 100).toFixed(0);
            yData.push(rate);
        }

        let chartData = {
            xData: xData,
            yData: [{
                type: 'bar',
                data: yData,
                barWidth: '15px',
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'top',
                            color: "#036EB8"
                        },
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [{
                                offset: 0,
                                color: '#0385DC'
                            }, {
                                offset: 1,
                                color: '#1f4e79'
                            }]
                        )
                    }
                }
            }]
        }

        //判断图表是否第一次绘制
        this.isHaveChart(Chart2, this.echartsComponnet2, this.data.chartSet2, chartData);
    },

    //处理图表数据-设备类型出勤率
    chartRateType(result) {
        //图表组件-设备类型出勤率
        this.echartsComponnet6 = this.selectComponent('#mychart6');

        //图表x轴日期
        let xData = [];
        result[0].attendance.forEach(item => {
            xData.push(item.day);
        });

        //图表y轴数据
        let yData = [];
        result.forEach(item => {
            let arr = [];
            let runs = item.attendance;
            for (let i = 0; i < runs.length; i++) {
                arr.push((runs[i].rate * 100).toFixed(0).replace(regexp, '$1'));
            }

            yData.push({
                type: 'bar',
                data: arr,
                name: item.key,
                // barWidth : '15px',
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'right'
                        }
                    }
                }
            });
        });

        let chartData = {
            xData: xData,
            yData: yData
        }

        let colors = ['#EAA321', '#D87530', '#F4CC81', '#F4BD57'];
        this.isHaveChart(Chart6, this.echartsComponnet6, this.data.chartSet6, chartData, 'vertical', colors);
    },

    //处理图表数据-设备运行时长
    chartHour(result) {
        //图表组件
        this.echartsComponnet5 = this.selectComponent('#mychart5');

        //x轴日期
        let xData = [];
        result[0].attendance.forEach(item => {
            xData.push(item.day);
        });

        //y轴数据
        let yData = [];
        result.forEach(item => {
            let arr = [];
            let runs = item.attendance;
            for (let i = 0; i < runs.length; i++) {
                arr.push(runs[i].rate.toFixed(1).replace(regexp, '$1'));
            }

            yData.push({
                type: 'bar',
                data: arr,
                name: item.key,
                // barWidth : '15px',
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: 'right'
                        }
                    }
                }
            });
        });

        let chartData = {
            xData: xData,
            yData: yData
        }

        let colors = ['#0376C2', '#3EA7EB', '#2B73A1', '#8EC9F0', '#01558C', '#444CEE'];
        this.isHaveChart(Chart5, this.echartsComponnet5, this.data.chartSet5, chartData, 'vertical', colors);
        Toast.clear();
    },

    //显示日历
    onShowDate() {
        this.setData({
            showDate: true,
            showTabbar: false
        })
        this.hideChart();
    },

    //隐藏日历
    onCloseDate() {
        this.setData({
            showDate: false,
            showTabbar: true
        })
        this.showChart();
    },

    //确认日期
    onConfirmDate(event) {
        const [start, end] = event.detail;
        this.setData({
            showDate: false,
            startTime: util.timeFormatDay(start),
            endTime: util.timeFormatDay(end)
        })

        //隐藏日历
        this.onCloseDate();

        //人员出勤率
        this.personRate();

        //设备出勤率
        this.findEquipmentAllRate();

        //设备类型出勤率、设备运行时长
        this.getChartData();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})